<?php
class UsersController extends AdminController{
	
	public function actionIndex(){
		$mUser = new Mapper_User($this->getDb());
		$this->userList = $mUser->getAll();
	}
	
	public function actionAdd(){
		$request = $this->getRequest();
		
		if($request->isPost()){
			
			$mUser = new Mapper_User($this->getDb());
			
			if(($user = $mUser->create($request->post))){
				if($user->user_pass == $request->post->user_passt){
					if($mUser->add($user)){
						die(header("location: /admin/users"));
					}else{
						$this->error = "Adding user failed";
					}
				}else{
					$this->error = "Passwords do not match";
				}
			}else{
				$this->error = "Creating user failed";
			}
		}
	}
}